local zhiyuan = fk.CreateSkill {
  name = "lvshi__zhiyuan&",
  mode_skill = true,
}

Fk:loadTranslationTable{
  ["lvshi__zhiyuan&"] = "支援",
  [":lvshi__zhiyuan&"] = "出牌阶段结束时，你可将一张暗置手牌交给一名己方角色，其明置之。",
  ["#lvshi__zhiyuan"] = "你可交给一名己方角色一张暗置手牌",
}

local DIY = require "packages/diy_utility/diy_utility"
local TT = require "packages/tuntian_studio/utility"
local ls = require "packages/lvshi/utility"

zhiyuan:addEffect(fk.EventPhaseEnd, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhiyuan.name) and player:getHandcardNum() > 0
    and player.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    local ids = table.filter(player:getCardIds("h"), function (c) return not TT.isShown(c) end)
    local targets = table.filter(player.room:getOtherPlayers(player), function (p)
      return ls.isFriend(player, p)
    end)
    local tar, card, _ = player.room:askToChooseCardsAndPlayers(player, {
      max_num = 1,
      min_num = 1,
      max_card_num = 1,
      min_card_num = 1,
      targets = targets,
      pattern = tostring(Exppattern{ id = ids }),
      prompt = "#lvshi__zhiyuan",
      cancelable = true,
    })
    if #tar > 0 and #card > 0 then
      event:setCostData(self, {target = tar[1], cards = card})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).target
    player.room:obtainCard(to, event:getCostData(self).cards, false, fk.ReasonGive, player, zhiyuan.name)
    DIY.showCards(to, event:getCostData(self).cards)
  end,
})

return zhiyuan